package net.mlike.openssp.server.controller;

import net.mlike.openssp.server.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by wallellen@hotmail.com on 5/24/18.
 */
@Controller
@RequestMapping("/html/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/index", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public String index() {
        return "system/role/index";
    }

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add() {
        return "system/role/form";
    }

    @RequestMapping(name = "/edit/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable("id") String id, Model model) {
        model.addAttribute("role", roleService.findById(id));
        return "system/role/form";
    }
}
